import { BinaryDecision } from "framework/FSM/DecisionTree/Decision";

 
/**
 * 判断PC携带的OPS是否满足任务需求
*/
export class DecisionIsOPSReady <T extends IStateArg<PowerCreep>> extends BinaryDecision<T>
{

    public testValue(arg:T): boolean
    {
        if(arg.entity)
        {
            if(!arg.entity.memory.taskid)
            {
                return false
            }
            const toptask =  arg.entity.ownerRoom().findTaskById<ITaskDeclare['pc']>(arg.entity.memory.taskid);
           
            if(toptask)
            {
                const powerinfo:{
                    className: PowerClassConstant;
                    level: number[];
                    cooldown: number;
                    effect?: number[];
                    range?: number;
                    ops?: number | number[];
                    duration?: number | number[];
                } = POWER_INFO[toptask.data.arg.POWER];
                if(powerinfo.ops)
                {
                    const storeops = arg.entity.store.getUsedCapacity(RESOURCE_OPS);
                    if(typeof powerinfo.ops == "number")
                    {
                        if(storeops>=powerinfo.ops)
                        {
                            return true;
                        }
                    }
                }
                else
                {
                    return true;
                }
            }
            return arg.entity.ticksToLive === undefined
        }
        return false;
    }

    value: any;


    public setValue(val: any)
    {
        this.value = val;
    }
}

